<template>
    <div>
      <div id="msform">
        <ul class="progressbar">
          <li class="active">
              <span class="text-one" v-if="!showNext">1</span>
              <i class="iconfont" v-else>&#xe661;</i>
              <span class="line_bg lbg-r"></span>
              <p class="f16">店铺信息</p>
          </li>
          <li :class="{active: showNext === true}">
              <span class="text-one">2</span>
              <span class="line_bg lbg-l"></span>
              <p class="f16">街道信息</p>
          </li>
        </ul>
        <fieldset class="store-info" style="border-color: transparent" v-if="!showNext">
          <form :model="formTop">
            <view class="f16 mt10 mb10">店铺名称</view>
            <div class='info-write flex align-center '>
              <i class='iconfont icon-dianpuguanli'></i>
              <input placeholder="请输入您的店铺名称" v-model="formTop.storeName"/>
            </div>
            <view class="f16 mt10 mb10">联系人</view>
            <div class='info-write flex align-center '>
              <i class='iconfont icon-yonghuming'></i>
              <input placeholder="请输入联系人姓名" v-model="formTop.userName"/>
            </div>
            <view class="f16 mt10 mb10">联系电话</view>
            <div class='info-write flex align-center '>
              <i class='iconfont icon-shouji'></i>
              <input placeholder="请输入联系人手机" type="number" maxlength="11" v-model="formTop.phone"/>
            </div>
            <section class="mt15">
              <i-button long="true" type='success' @tap = "nextStep">下一步</i-button>
            </section>
          </form>
        </fieldset>
        <fieldset class="store-info" style="border-color: transparent;" v-else>
            <form :model="formTop">
              <view class="f16 mt10 mb10">地区</view>
              <view class='info-write flex align-center '>
                <i class='iconfont icon-75'></i>
                <input placeholder="请选择店铺所在区域" @focus="popupVisible = true" v-model="formTop.storeArea"/>
              </view>
              <view class="f16 mt10 mb10">地图标注</view>
              <view class='info-write flex align-center '>
                <i class='iconfont icon-xiaotuziCduan-1'></i>
                <input placeholder="请在地图上标注店铺位置" @focus="selectMap" v-model="formTop.storePosition"/>
              </view>
              <view class="f16 mt10 mb10">街道</view>
              <view class='info-write flex align-center '>
                <i class='iconfont icon-xiaotuziCduan-1'></i>
                <input placeholder="请输入详情街道" v-model="formTop.storeDetail"/>
              </view>
              <footer class="mt15">
                <button class="flex1 mr10" style="background: #78adaa;" size="normal" type="primary" @click="showNext = false" >上一步</button>
                <button class="flex1" size="normal" type="success" @tap="nextDetail">提交</button>
              </footer>
            </form>
        </fieldset>
        <div v-show="popupVisible" class="select-area">
          <header class="h50 f16 tc" style="line-height: 50px;">请选择地址
            <i class="iconfont" @click="closeModeal">&#xe6e9;</i>
          </header>
          <main>
            <ul>
              <li class="f16" style="background: #efefef" v-for="datas in data" :key="datas.index" @click="getSelect(datas.label)" :class="{privince: select === datas.label}">
                {{datas.label}}
              </li>
            </ul>
            <ul>
              <li class="f16 center-area" v-for="next in selectChildren" :key="next.index" @click="selectnext =  next.label" :class="{selectNext: selectnext === next.label}">
                {{next.label}}
              </li>
            </ul>
            <ul>
              <li class="f16" v-for="item in selectChildren" :key="item.index" @click="selectLast(item.label)" :class="{selectNext: selectlast === item.label}">
                {{item.label}}
              </li>
            </ul>
          </main>
        </div>
        <div v-show="selectmap" class="select-area">
          <map id="1" class='map' :latitude='latitude' :longitude='longitude' :scale='scale' :markers='markers' :control="control" @callouttap="calloutTap">
          </map>
        </div>
      </div>
    </div>
</template>

<script type="ECMAScript 6">
    export default {
        name: 'add-store',
        data () {
            return {
              updataInfor: false,
              select: '北京',
              selectnext: '故宫',
              selectlast: '天坛',
              showNext: false,
              selectmap: false,
              popupVisible: false,
              formTop: {
                      storeName: '',
                      userName: '',
                      phone: '',
                      storeArea: '',
                      storePosition: '',
                      storeDetail: ''

              },
              data: [{
                value: 'beijing',
                label: '北京',
                children: [
                  {
                    value: 'gugong',
                    label: '故宫'
                  },
                  {
                    value: 'tiantan',
                    label: '天坛'
                  },
                  {
                    value: 'wangfujing',
                    label: '王府井'
                  }
                ]
              }, {
                value: 'jiangsu',
                label: '江苏',
                children: [
                  {
                    value: 'nanjing',
                    label: '南京',
                    children: [
                      {
                        value: 'fuzimiao',
                        label: '夫子庙'
                      }
                    ]
                  },
                  {
                    value: 'suzhou',
                    label: '苏州',
                    children: [
                      {
                        value: 'zhuozhengyuan',
                        label: '拙政园'
                      },
                      {
                        value: 'shizilin',
                        label: '狮子林'
                      }
                    ]
                  }
                ]
              },
                {
                  value: 'jiangsu',
                  label: '湖南',
                  children: [
                    {
                      value: 'nanjing',
                      label: '南京',
                      children: [
                        {
                          value: 'fuzimiao',
                          label: '夫子庙'
                        }
                      ]
                    },
                    {
                      value: 'suzhou',
                      label: '苏州',
                      children: [
                        {
                          value: 'zhuozhengyuan',
                          label: '拙政园'
                        },
                        {
                          value: 'shizilin',
                          label: '狮子林'
                        }
                      ]
                    }
                  ]
                },
                {
                  value: '安徽',
                  label: '安徽',
                  children: [
                    {
                      value: 'nanjing',
                      label: '南京',
                      children: [
                        {
                          value: 'fuzimiao',
                          label: '夫子庙'
                        }
                      ]
                    },
                    {
                      value: 'suzhou',
                      label: '苏州',
                      children: [
                        {
                          value: 'zhuozhengyuan',
                          label: '拙政园'
                        },
                        {
                          value: 'shizilin',
                          label: '狮子林'
                        }
                      ]
                    }
                  ]
                }],
              selectChildren: [
                {
                  value: 'gugong',
                  label: '故宫'
                },
                {
                  value: 'tiantan',
                  label: '天坛'
                },
                {
                  value: 'wangfujing',
                  label: '王府井'
                }
              ],
              scale: 18,
              latitude: "",
              longitude: "",
              markers: [],
              control: []
            };
          },
        methods: {
          nextDetail () {
            let url = '../store-detail/main?id=' + JSON.stringify(this.formTop);
            wx.navigateTo({ url});
          },
          regionChange (res) {
            console.log(res);
          },
          selectMap () {
            let status = (this.formTop.storeArea === '' && wx.showToast({
              title: '您未选择店铺所在的区域',
              icon: 'none',
              duration: 2000
            }));
            if (status === false) {
              this.selectmap = true;
              const that = this;
              wx.getLocation({
                type: "wgs84",
                success: function (res) {
                    that.latitude = res.latitude,
                    that.longitude = res.longitude,
                    that.markers = [{
                      id: "1",
                      latitude: res.latitude,
                      longitude: res.longitude,
                      width: 50,
                      height: 50,
                      iconPath: "./location.png"
                    }]
                },
              });
            }
          },
          closeModeal () {
            this.formTop.storeArea = this.select + this.selectnext + this.selectlast;
            this.popupVisible = false;
          },
          selectLast (index) {
            this.selectlast = index;
            this.formTop.storeArea = this.select + this.selectnext + this.selectlast;
            this.popupVisible = false;
          },
          getSelect (index) {
            this.select = index;
            this.data.forEach(datas => {
              if (datas.label === index) {
                this.selectChildren = datas.children;
                this.selectnext = datas.children[0].label;
                this.selectlast = datas.children[0].label;
              }
            });
          },
          nextStep () {
            var regBox = {
              regMobile: /^0?1[3|4|5|8][0-9]\d{8}$/ // 手机号码正则表达式
            };
            if (this.formTop.storeName === '') {
              wx.showToast({
                title: '您未填写店铺名！',
                duration: 2000,
                icon: 'none'
              });
            } else if (this.formTop.userName === '') {
              wx.showToast({
                title: '您未填写姓名！',
                duration: 2000,
                icon: 'none'
              });
            } else if (this.formTop.phone === '') {
              wx.showToast({
                title: '您未填写手机号！',
                duration: 2000,
                icon: 'none'
              })
            } else if (!regBox.regMobile.test(this.formTop.phone)) {
              wx.showToast({
                title: '您填写的手机格式不正确！',
                duration: 2000,
                icon: 'none'
              })
            }else {
              this.showNext = true;
            }
          }
        }
    };
</script>

<style lang="stylus" scoped>
  .next-step
      margin 0!important; flex 1!important;
  .info-write
    background #fff; padding 5px 0 5px 10px; border-radius 3px; height 40px; line-height 40px;
    i
      font-size 24px; color #41B962;
    input
      padding-left 15px; font-size 13px;
  #msform
    width: 100%;position: relative;
    .progressbar
      display flex; margin-top: 53px;overflow: hidden; text-align: center; 
      li
        flex 1; position relative;
      .text-one
        position: relative;
        z-index: 5;
        display: inline-block;
        width: 23px;
        height: 23px;
        line-height: 23px;
        font-size: 16px;
        background: #CACACA;
        border-radius: 50%;
      .line_bg
        height:2px;
        background: #D7D7D7;
        display: inline-block;
        width: 45%;
        top: 13px;
        position: absolute;
        z-index: 1;
      .lbg-l
          left: 0;
      .lbg-r
          right: 0;
    .progressbar .active
      color: #27AE60;
      span
        background: #27AE60;
        color: #ffffff;
      i
        display: inline-block; width: 23px; height: 23px; font-size: 24px; color: #27AE60; line-height 23px;vertical-align: top;
    .mint-button--primary
       background #27AE60;
    .mint-button::after
      background-color  transparent;
    footer
      display flex; align-items center;
      button
       height 40px; background #27AE60;color #fff;border-radius 2px; font-size 18px;line-height 40px;
  .select-area
      position fixed; z-index 300; top 0;left 0; width 100%;height 100%; background #fff;
      header
        position relative;
        i
          position absolute; right 20px;
      main
        display flex;
        ul
          flex 1; height 100%; height 100%;
          li
            position: relative;  display: block;  margin-bottom: -1px;  background-color: #fff;  border: 1px solid #dedede;  padding:8px 5px;  font-size:14px;  text-align: center;  color: #848484;  word-wrap: normal;  text-overflow: ellipsis;  white-space: nowrap;  overflow: hidden;
          .center-area
            border-width 1px 0;
          .privince
            background #fff!important;
          .selectNext
            background #efefef;
      .map
        width 100%; height 100%;
  #forms{ height:30px; line-height:30px; background:#F6F6F6; position:absolute; bottom:0px; left:0px; z-index:3; width:100%; border-top:1px solid #C2D1D8; padding:3px 0px;}
  #forms span{ padding:2px 8px;}
  #forms a{ background:#336FC9; color:#FFF; padding:3px 10px; border-radius:15px; text-decoration:none;}
  #forms a:hover{ background:#333;}
  #map_body{width:100%; height:100%; z-index:1; top:0; left:0;}
  #tip{ position:absolute; z-index:2; padding:5px 15px; top:20px; left:65px; background:#333; color:#fff; border-radius:15px; font-weight:bold;}
  #search{ position:absolute; z-index:2; padding:3px 15px; top:20px; left:180px; background:#333; color:#fff; border-radius:15px; font-weight:bold;}
  #search input{ border: 1px solid #333;}
</style>
<style lang="stylus">
  .store-info
    width 80%; margin 12% auto 0 auto;
  .mint-popup
    width 100%; height 100%;
  .ivu-form .ivu-form-item-label
    font-size 15px!important;
  .ivu-input
    height 40px; font-size 13px; border-color transparent;
  .ivu-input:hover
    border-color transparent;
  .ivu-input-prefix i, .ivu-input-suffix i
    line-height 40px; color #27AE60; font-size 20px;
</style>
